#pragma once
#include <iostream>
#include <memory>
#include <stdio.h>

#include "request.h"

using namespace std;

//抽象处理者Leader
class Leader{
public:
	Leader(string name){
		this->name = name;
	};
	
	void setSuccessor(weak_ptr<Leader> successor){
		this->successor = successor;
	};
	
	virtual void handleRequest(const LeaveRequest &request) = 0;
	
protected:
	string name;
	weak_ptr<Leader> successor;
}; 


//具体处理者Director
class Director : public Leader{
public:
	Director(string name) : Leader(name){
		
	}
	
	void handleRequest(const LeaveRequest &request){
		//处理请求 
		if(request.getLeaveDays()<3){
			cout << "主任" << this->name << "审批员工" << request.getLeaveName() << "的请假条，请假天数为"
			 	 << request.getLeaveDays() << "天." << endl; 
		}else{
			//无法处理此请求，则交给上级处理 
			if(this->successor.lock()!=nullptr){
				this->successor.lock()->handleRequest(request);
			}
		}
	}
	
}; 

//具体处理者Manager
class Manager : public Leader{
public:
	Manager(string name) : Leader(name){
		
	}
	
	void handleRequest(const LeaveRequest &request){
		//处理请求 
		if(request.getLeaveDays()<10){
			cout << "经理" << this->name << "审批员工" << request.getLeaveName() << "的请假条，请假天数为"
			 	 << request.getLeaveDays() << "天." << endl; 
		}else{
			//无法处理此请求，则交给上级处理 
			if(this->successor.lock()!=nullptr){
				this->successor.lock()->handleRequest(request);
			}
		}
	}
	
}; 



//具体处理者GeneralManager
class GeneralManager : public Leader{
public:
	GeneralManager(string name) : Leader(name){
		
	}
	
	void handleRequest(const LeaveRequest &request){
		//处理请求 
		if(request.getLeaveDays()<30){
			cout << "总经理" << this->name << "审批员工" << request.getLeaveName() << "的请假条，请假天数为"
			 	 << request.getLeaveDays() << "天." << endl; 
		}else{
			cout << "莫非" << request.getLeaveName() << "想辞职,居然请假" 
			 	 << request.getLeaveDays() << "天." << endl; 
		}
	}
	
}; 
